#include<stdio.h>
#include<unistd.h>
#include<string.h>
#define STYLE '#'
#define NUM 101
void progress_bar(double total, double current)
{
	char str[NUM] = { 0 };
	memset(str, ' ', strlen(str));
	static int len = 0;
	char lable[5] = "-\\|/";
	double percent =  current * 100 / total;
	for(int i = 0; i <= percent; ++i)//注意这里需要<=
	{
		str[i] = STYLE;
	}
	len += 1;
	len %= 4;
	if(percent > 100)
	{
		percent = 100;
	}
	printf("\r[%-100s][%.2f%%][%c]", str, percent, lable[len]);//注意这里需要的格式符，需要%-100s（负数为左对齐,%%表示转义%）
	fflush(stdout);//刷新缓冲区，使当前内容及时输出
}
